<template>
  <div>
    <el-carousel height="900px" interval="2000">
      <el-carousel-item class="el-carousel-item" v-for="(item, index) in swiperData" :key="index">
        <img
          v-if="item.fileType == 'image'"
          :src="$t(`messages.news.swiperList[${index}].image`)"
          alt=""
          srcset=""
        />
        <video class="video" v-else autoplay loop>
          <source :src="$t(`messages.news.swiperList[${index}].image`)" type="video/mp4" />
        </video>
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script setup>
import { newSlideshow } from '@/http/api/news.js'

import { ref, reactive, onMounted } from 'vue'
import Zh from '@/assets/i18n/langs/zh.js'
import En from '@/assets/i18n/langs/en.js'
let typeAll = {
  image: ['png', 'jpg', 'jpeg', 'svg'],
  video: ['avi', 'mpeg', 'mp4', 'wmv', 'flv', 'mov', 'mkv', 'rmvb', '3gp']
}
let swiperData = ref([])
let pageData = reactive({
  page: 1,
  size: 50
})
const newSlideshowList = async () => {
  let res = await newSlideshow(pageData)
  Zh.messages.news.swiperList = res.res.map((item) => {
    return {
      title: item.title,
      image: item.image
    }
  })
  En.messages.news.swiperList = res.res.map((item) => {
    return {
      title: item.title,
      image: item.image
    }
  })

  swiperData.value = res.res.map((item) => {
    let type = item.image.split('.')[item.image.split('.').length - 1]
    let size = ''
    for (const key in typeAll) {
      typeAll[key].forEach((item1) => {
        if (item1 == type) {
          size = key
        }
      })
    }
    return {
      ...item,
      fileType: size
    }
  })
}
onMounted(() => {
  newSlideshowList()
})
</script>

<style lang="scss" scoped>
.homeBack {
  background: #131718;
}
.el-carousel-item {
  img {
    width: 100%;
    height: 100%;
  }
}
.swiper {
  height: 700px;
  width: 1400px;
  margin: 0;
}
.caseBox {
  height: 820px;
  padding: 15px;
  display: flex;
  justify-content: space-between;
}
.caseLeftBox {
  width: 500px;
  padding: 20px;
  .title {
    font-size: 32px;
    font-weight: bold;
    color: #ffdd00;
  }
  .size {
    width: 350px;
    margin-top: 50px;
    color: #ffffff;
    white-space: pre-wrap; /* 保留空白符序列，但是当到达容器边界时进行换行 */
    overflow-wrap: break-word; /* 在长单词或URL地址内部进行换行 */
    word-break: break-all; /* 允许在任意字符间断开（用于CJK文字等） */
  }
}
.title {
  font-size: 32px;
  font-weight: bold;
  color: #ffdd00;
}
.size {
  width: 750px;
  margin-top: 10px;
  color: #ffffff;
  white-space: pre-wrap; /* 保留空白符序列，但是当到达容器边界时进行换行 */
  overflow-wrap: break-word; /* 在长单词或URL地址内部进行换行 */
  word-break: break-all; /* 允许在任意字符间断开（用于CJK文字等） */
}
.video {
  height: 950px;
  width: 100%;
  padding: 10px 140px;
  background: #000101 !important;
  cursor: pointer;
}
.CorporateSize {
  display: flex;
  justify-content: space-between;
  padding: 0 30px;

  .title {
    font-size: 32px;
    font-weight: bold;
    color: #ffdd00;
  }
  .size {
    width: 250px;
    margin-top: 10px;
    font-size: 20px;
    color: #5c5c5c;
    white-space: pre-wrap; /* 保留空白符序列，但是当到达容器边界时进行换行 */
    overflow-wrap: break-word; /* 在长单词或URL地址内部进行换行 */
    word-break: break-all; /* 允许在任意字符间断开（用于CJK文字等） */
  }
}
</style>